package com.fcscs.cservice.client.main.inroomdining;

import com.extjs.gxt.ui.client.event.BaseEvent;
import com.extjs.gxt.ui.client.event.ButtonEvent;
import com.extjs.gxt.ui.client.event.Events;
import com.extjs.gxt.ui.client.event.Listener;
import com.extjs.gxt.ui.client.event.SelectionChangedEvent;
import com.extjs.gxt.ui.client.event.SelectionChangedListener;
import com.extjs.gxt.ui.client.event.SelectionListener;
import com.extjs.gxt.ui.client.store.ListStore;
import com.extjs.gxt.ui.client.widget.HorizontalPanel;
import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.extjs.gxt.ui.client.widget.VerticalPanel;
import com.extjs.gxt.ui.client.widget.form.ComboBox.TriggerAction;
import com.extjs.gxt.ui.client.widget.form.Field;
import com.extjs.gxt.ui.client.widget.form.FormPanel;
import com.extjs.gxt.ui.client.widget.form.TextField;
import com.extjs.gxt.ui.client.widget.form.Validator;
import com.extjs.gxt.ui.client.widget.layout.ColumnData;
import com.extjs.gxt.ui.client.widget.layout.ColumnLayout;
import com.fcscs.core.gwt.common.CoreConstants;
import com.fcscs.core.gwt.common.CoreEnums.SubmitType;
import com.fcscs.core.gwt.common.FormSubmitListener;
import com.fcscs.core.gwt.common.ui.BaseFormDialog;
import com.fcscs.core.gwt.common.ui.FcsFields.EasyClearCombobox;
import com.fcscs.core.gwt.common.ui.FcsFields.FormButton;
import com.fcscs.core.gwt.common.ui.FcsFormPanel;
import com.fcscs.core.gwt.common.ui.IEFriendlyDateField;
import com.fcscs.cservice.client.common.CServiceConstants;
import com.fcscs.cservice.client.common.model.restaurants.BookingStatusGWTEnum;
import com.fcscs.cservice.client.common.model.restaurants.BookingStatusModelData;
import com.fcscs.cservice.client.common.model.restaurants.BookingViewModelData;
import com.fcscs.cservice.client.common.model.restaurants.GuestProfileTypeEnumModelData;
import com.fcscs.cservice.client.common.model.restaurants.GuestProfileTypeGWTEnum;
import com.fcscs.cservice.client.common.model.restaurants.RestaurantSearchItemModel;
import com.fcscs.cservice.client.common.model.restaurants.RestaurantsSearchItemGWTEnum;
import com.fcscs.cservice.client.common.model.restaurants.RestaurantsSearchItemsGWTEnumModelData;
import com.fcscs.cservice.domain.model.BookingView;
import com.fcscs.share.gwt.common.ShareGWTConstants;

public class InRoomDiningAdvancedDialog extends BaseFormDialog<BookingView> implements FormSubmitListener<BookingViewModelData>{


	protected VerticalPanel vp;
	protected FormPanel formPanel;
	protected ListStore<RestaurantsSearchItemsGWTEnumModelData> searchItemListStore;
	protected ListStore<RestaurantsSearchItemsGWTEnumModelData> searchItemListStore1;
	protected ListStore<RestaurantsSearchItemsGWTEnumModelData> searchItemListStore2;
	protected ListStore<RestaurantsSearchItemsGWTEnumModelData> searchItemListStore3;
	protected EasyClearCombobox<RestaurantsSearchItemsGWTEnumModelData> searchItemCombo1;
	protected EasyClearCombobox<RestaurantsSearchItemsGWTEnumModelData> searchItemCombo2;
	protected EasyClearCombobox<RestaurantsSearchItemsGWTEnumModelData> searchItemCombo3;
	protected EasyClearCombobox<BookingStatusModelData> bookingStatusCombo1;
	protected EasyClearCombobox<BookingStatusModelData> bookingStatusCombo2;
	protected EasyClearCombobox<BookingStatusModelData> bookingStatusCombo3;
	protected ListStore<BookingStatusModelData> bookingStatusListStore;
	protected EasyClearCombobox<GuestProfileTypeEnumModelData> guestTypeCombo1;
	protected EasyClearCombobox<GuestProfileTypeEnumModelData> guestTypeCombo2;
	protected EasyClearCombobox<GuestProfileTypeEnumModelData> guestTypeCombo3;

	protected LayoutContainer lc1;
	protected LayoutContainer lc2;
	protected LayoutContainer lc3;
	protected TextField<String> firstName1;
	protected TextField<String> firstName2;
	protected TextField<String> firstName3;
	protected TextField<String> lastName1;
	protected TextField<String> lastName2;
	protected TextField<String> lastName3;
	protected IEFriendlyDateField fromDateField1;
	protected IEFriendlyDateField fromDateField2;
	protected IEFriendlyDateField fromDateField3;
	protected IEFriendlyDateField toDateField1;
	protected IEFriendlyDateField toDateField2;
	protected IEFriendlyDateField toDateField3;
	
	protected ListStore<GuestProfileTypeEnumModelData> guestTypeStore;

	protected FormButton searchButton;
	protected static InRoomDiningAdvancedDialog INSTANCE;
	protected RestaurantSearchItemModel searchItemModel;
	protected MyFormPanel myFormPanel;
	protected HorizontalPanel searchBtnLeftHp;
	protected HorizontalPanel searchBtnRightHp;
	protected HorizontalPanel searchBtnBarHp;
	protected FormSubmitListener<BookingView> listener;

	public static InRoomDiningAdvancedDialog getInstance(FormSubmitListener<BookingView> listener) {
		if (null == INSTANCE) {
			INSTANCE = new InRoomDiningAdvancedDialog();
		}
//		INSTANCE.listener = listener;
		INSTANCE.setHeading(CServiceConstants.CSERVICE_CONSTANTS.restaurantView());
		return INSTANCE;
	}

	public InRoomDiningAdvancedDialog() {
		if (null == INSTANCE) {
			myFormPanel = new MyFormPanel(null);
		}
		myFormPanel.setLabelWidth(120);
		add(myFormPanel);
		setSize(560, 250);
	}

	public class MyFormPanel extends FcsFormPanel<BookingView> {

		protected MyFormPanel(FormSubmitListener<BookingView> l) {
			super(l);
			setHeaderVisible(false);

			if (vp == null) {
				vp = new VerticalPanel();
				vp.setId("RestaurantsPanel_vp_id");
				vp.setSpacing(0);

				formPanel = new FormPanel();
				formPanel.setId("RestaurantsPanel_formPanel_id");
				formPanel.setSize(540, 150);
				formPanel.setHeaderVisible(false);
				vp.add(formPanel);

				lc1 = new LayoutContainer();
				lc1.setLayout(new ColumnLayout());

				lc2 = new LayoutContainer();
				lc2.setLayout(new ColumnLayout());

				lc3 = new LayoutContainer();
				lc3.setLayout(new ColumnLayout());

				searchItemListStore = new ListStore<RestaurantsSearchItemsGWTEnumModelData>();
				for (RestaurantsSearchItemGWTEnum fsi : RestaurantsSearchItemGWTEnum.values()) {
					searchItemListStore.add(new RestaurantsSearchItemsGWTEnumModelData(fsi));
				}
				searchItemListStore1 = new ListStore<RestaurantsSearchItemsGWTEnumModelData>();
				searchItemListStore2 = new ListStore<RestaurantsSearchItemsGWTEnumModelData>();
				searchItemListStore3 = new ListStore<RestaurantsSearchItemsGWTEnumModelData>();

				searchItemCombo1 = new EasyClearCombobox<RestaurantsSearchItemsGWTEnumModelData>();
				searchItemCombo1.setId("RestaurantsPanel_searchItemCombo1");
				searchItemCombo1.setStore(searchItemListStore1);
				searchItemCombo1.setValue(searchItemListStore.getAt(0));
				searchItemCombo1.setTriggerAction(TriggerAction.ALL);
				searchItemCombo1.setDisplayField(CoreConstants.FULLTNAME);
				searchItemCombo1.setForceSelection(true);
				searchItemCombo1.setAllowBlank(false);
				searchItemCombo1
						.addSelectionChangedListener(new SelectionChangedListener<RestaurantsSearchItemsGWTEnumModelData>() {

							@Override
							public void selectionChanged(
									SelectionChangedEvent<RestaurantsSearchItemsGWTEnumModelData> se) {
								searchItemView(searchItemCombo1.getValue().getEnum().getIndex(), 1);
								buildStore();
							}
						});
				lc1.add(searchItemCombo1, new ColumnData(150));

				searchItemCombo2 = new EasyClearCombobox<RestaurantsSearchItemsGWTEnumModelData>();
				searchItemCombo2.setId("RestaurantsPanel_searchItemCombo2");
				searchItemCombo2.setStore(searchItemListStore2);
				searchItemCombo2.setValue(searchItemListStore.getAt(1));
				searchItemCombo2.setTriggerAction(TriggerAction.ALL);
				searchItemCombo2.setDisplayField(CoreConstants.FULLTNAME);
				searchItemCombo2.setForceSelection(true);
				searchItemCombo2.setAllowBlank(false);
				searchItemCombo2
						.addSelectionChangedListener(new SelectionChangedListener<RestaurantsSearchItemsGWTEnumModelData>() {

							@Override
							public void selectionChanged(
									SelectionChangedEvent<RestaurantsSearchItemsGWTEnumModelData> se) {
								searchItemView(searchItemCombo2.getValue().getEnum().getIndex(), 2);
								buildStore();
							}
						});
				lc2.add(searchItemCombo2, new ColumnData(150));

				searchItemCombo3 = new EasyClearCombobox<RestaurantsSearchItemsGWTEnumModelData>();
				searchItemCombo3.setId("RestaurantsPanel_searchItemCombo3");
				searchItemCombo3.setStore(searchItemListStore3);
				searchItemCombo3.setValue(searchItemListStore.getAt(2));
				searchItemCombo3.setTriggerAction(TriggerAction.ALL);
				searchItemCombo3.setDisplayField(CoreConstants.FULLTNAME);
				searchItemCombo3.setForceSelection(true);
				searchItemCombo3.setAllowBlank(false);
				searchItemCombo3
						.addSelectionChangedListener(new SelectionChangedListener<RestaurantsSearchItemsGWTEnumModelData>() {

							@Override
							public void selectionChanged(
									SelectionChangedEvent<RestaurantsSearchItemsGWTEnumModelData> se) {
								searchItemView(searchItemCombo3.getValue().getEnum().getIndex(), 3);
								buildStore();
							}
						});
				lc3.add(searchItemCombo3, new ColumnData(150));

				firstName1 = new TextField<String>();
				firstName1.setId("RestaurantsPanel_firstName1");
				firstName1.setStyleAttribute(CServiceConstants.CSS_MARGINLEFT, "20px");
				firstName1.setEmptyText(CoreConstants.CORE_CONSTANTS.firstname());
				firstName1.setVisible(false);
				lc1.add(firstName1, new ColumnData(150));
				firstName1.setValidator(new Validator() {

					@Override
					public String validate(Field<?> field, String value) {
						if (!firstName1.isVisible()) {
							return null;
						} else if (null != value && (!value.trim().isEmpty())
								&& (value.trim().length() < 2 || value.trim().length() > 255)) {
							return ShareGWTConstants.SHARE_GWT_MESSAGES.nameValid(
									CoreConstants.CORE_CONSTANTS.firstname(), 2, 255);
						}
						return null;
					}
				});
				
				

				firstName2 = new TextField<String>();
				firstName2.setId("RestaurantsPanel_firstName2");
				firstName2.setStyleAttribute(CServiceConstants.CSS_MARGINLEFT, "20px");
				firstName2.setEmptyText(CoreConstants.CORE_CONSTANTS.firstname());
				firstName2.setVisible(false);
				lc2.add(firstName2, new ColumnData(150));
				firstName2.setValidator(new Validator() {
					
					@Override
					public String validate(Field<?> field, String value) {
						if (!firstName2.isVisible()) {
							return null;
						} else if (null != value && (!value.trim().isEmpty())
								&& (value.trim().length() < 2 || value.trim().length() > 255)) {
							return ShareGWTConstants.SHARE_GWT_MESSAGES.nameValid(
									CoreConstants.CORE_CONSTANTS.firstname(), 2, 255);
						}
						return null;
					}
				});

				firstName3 = new TextField<String>();
				firstName3.setId("RestaurantsPanel_firstName3");
				firstName3.setStyleAttribute(CServiceConstants.CSS_MARGINLEFT, "20px");
				firstName3.setEmptyText(CoreConstants.CORE_CONSTANTS.firstname());
				firstName3.setVisible(false);
				lc3.add(firstName3, new ColumnData(150));
				firstName3.setValidator(new Validator() {

					@Override
					public String validate(Field<?> field, String value) {
						if (!firstName3.isVisible()) {
							return null;
						} else if (null != value && (!value.trim().isEmpty())
								&& (value.trim().length() < 2 || value.trim().length() > 255)) {
							return ShareGWTConstants.SHARE_GWT_MESSAGES.nameValid(
									CoreConstants.CORE_CONSTANTS.firstname(), 2, 255);
						}
						return null;
					}
				});

				lastName1 = new TextField<String>();
				lastName1.setId("RestaurantsPanel_lastName1");
				lastName1.setStyleAttribute(CServiceConstants.CSS_MARGINLEFT, "20px");
				lastName1.setEmptyText(CoreConstants.CORE_CONSTANTS.lastname());
				lastName1.setVisible(false);
				lc1.add(lastName1, new ColumnData(150));
				lastName1.setValidator(new Validator() {
					@Override
					public String validate(Field<?> field, String value) {
						if (!lastName1.isVisible()) {
							return null;
						} else if (null != value && (!value.trim().isEmpty())
								&& (value.trim().length() < 2 || value.trim().length() > 255)) {
							return ShareGWTConstants.SHARE_GWT_MESSAGES.nameValid(
									CoreConstants.CORE_CONSTANTS.lastname(), 2, 255);
						}
						return null;
					}
				});
				

				lastName2 = new TextField<String>();
				lastName2.setId("RestaurantsPanel_lastName2");
				lastName2.setStyleAttribute(CServiceConstants.CSS_MARGINLEFT, "20px");
				lastName2.setEmptyText(CoreConstants.CORE_CONSTANTS.lastname());
				lastName2.setVisible(false);
				lc2.add(lastName2, new ColumnData(150));
				lastName2.setValidator(new Validator() {
					@Override
					public String validate(Field<?> field, String value) {
						if (!lastName2.isVisible()) {
							return null;
						} else if (null != value && (!value.trim().isEmpty())
								&& (value.trim().length() < 2 || value.trim().length() > 255)) {
							return ShareGWTConstants.SHARE_GWT_MESSAGES.nameValid(
									CoreConstants.CORE_CONSTANTS.lastname(), 2, 255);
						}
						return null;
					}
				});

				lastName3 = new TextField<String>();
				lastName3.setId("RestaurantsPanel_lastName3");
				lastName3.setStyleAttribute(CServiceConstants.CSS_MARGINLEFT, "20px");
				lastName3.setEmptyText(CoreConstants.CORE_CONSTANTS.lastname());
				lastName3.setVisible(false);
				lc3.add(lastName3, new ColumnData(150));
				lastName3.setValidator(new Validator() {
					@Override
					public String validate(Field<?> field, String value) {
						if (!lastName3.isVisible()) {
							return null;
						} else if (null != value && (!value.trim().isEmpty())
								&& (value.trim().length() < 2 || value.trim().length() > 255)) {
							return ShareGWTConstants.SHARE_GWT_MESSAGES.nameValid(
									CoreConstants.CORE_CONSTANTS.lastname(), 2, 255);
						}
						return null;
					}
				});
				
				bookingStatusListStore = new ListStore<BookingStatusModelData>();
				for(BookingStatusGWTEnum bsg : BookingStatusGWTEnum.values()){
					bookingStatusListStore.add(new BookingStatusModelData(bsg));
				}
				bookingStatusCombo1 = new EasyClearCombobox<BookingStatusModelData>();
				bookingStatusCombo1.setId("RestaurantsPanel_reservationStatusCombobox1");
				bookingStatusCombo1.setStyleAttribute(CServiceConstants.CSS_MARGINLEFT, "20px");
				bookingStatusCombo1.setEmptyText("Booking Status");
				bookingStatusCombo1.setTriggerAction(TriggerAction.ALL);
				bookingStatusCombo1.setDisplayField(CoreConstants.FULLTNAME);
				bookingStatusCombo1.setStore(bookingStatusListStore);
				bookingStatusCombo1.setForceSelection(true);
				bookingStatusCombo1.setVisible(false);
				lc1.add(bookingStatusCombo1, new ColumnData(150));

				bookingStatusCombo2 = new EasyClearCombobox<BookingStatusModelData>();
				bookingStatusCombo2.setId("RestaurantsPanel_reservationStatusCombo2");
				bookingStatusCombo2.setDisplayField(CoreConstants.FULLTNAME);
				bookingStatusCombo2.setStyleAttribute(CServiceConstants.CSS_MARGINLEFT, "20px");
				bookingStatusCombo2.setEmptyText("Booking Status");
				bookingStatusCombo2.setTriggerAction(TriggerAction.ALL);
				bookingStatusCombo2.setStore(bookingStatusListStore);
				bookingStatusCombo2.setForceSelection(true);
				bookingStatusCombo2.setVisible(false);
				lc2.add(bookingStatusCombo2, new ColumnData(150));

				bookingStatusCombo3 = new EasyClearCombobox<BookingStatusModelData>();
				bookingStatusCombo3.setId("RestaurantsPanel_reservationStatusCombo3");
				bookingStatusCombo3.setDisplayField(CoreConstants.FULLTNAME);
				bookingStatusCombo3.setStyleAttribute(CServiceConstants.CSS_MARGINLEFT, "20px");
				bookingStatusCombo3.setEmptyText("Booking Status");
				bookingStatusCombo3.setTriggerAction(TriggerAction.ALL);
				bookingStatusCombo3.setStore(bookingStatusListStore);
				bookingStatusCombo3.setForceSelection(true);
				bookingStatusCombo3.setVisible(false);
				lc3.add(bookingStatusCombo3, new ColumnData(150));

//				restaurantCombo1 = new EasyClearCombobox<ReservationStatusModelData>();
//				restaurantCombo1.setId("RestaurantsPanel_reservationStatusCombo3");
//				restaurantCombo1.setStyleAttribute(CServiceConstants.CSS_MARGINLEFT, "20px");
//				restaurantCombo1.setEmptyText(CServiceConstants.CSERVICE_CONSTANTS.restaurant());
//				restaurantCombo1.setDisplayField(CServiceConstants.STATUS);
//				restaurantCombo1.setTriggerAction(TriggerAction.ALL);
//				restaurantCombo1.setStore(bookingStatusListStore);
//				restaurantCombo1.setForceSelection(true);
//				restaurantCombo1.setVisible(false);
//				lc1.add(restaurantCombo1, new ColumnData(150));
//
//				restaurantCombo2 = new EasyClearCombobox<ReservationStatusModelData>();
//				restaurantCombo2.setId("RestaurantsPanel_reservationStatusCombo3");
//				restaurantCombo2.setStyleAttribute(CServiceConstants.CSS_MARGINLEFT, "20px");
//				restaurantCombo2.setEmptyText(CServiceConstants.CSERVICE_CONSTANTS.restaurant());
//				restaurantCombo2.setDisplayField(CServiceConstants.STATUS);
//				restaurantCombo2.setTriggerAction(TriggerAction.ALL);
//				restaurantCombo2.setStore(bookingStatusListStore);
//				restaurantCombo2.setForceSelection(true);
//				restaurantCombo2.setVisible(false);
//				lc2.add(restaurantCombo2, new ColumnData(150));
//
//				restaurantCombo3 = new EasyClearCombobox<ReservationStatusModelData>();
//				restaurantCombo3.setId("RestaurantsPanel_reservationStatusCombo3");
//				restaurantCombo3.setStyleAttribute(CServiceConstants.CSS_MARGINLEFT, "20px");
//				restaurantCombo3.setEmptyText(CServiceConstants.CSERVICE_CONSTANTS.restaurant());
//				restaurantCombo3.setDisplayField(CServiceConstants.STATUS);
//				restaurantCombo3.setTriggerAction(TriggerAction.ALL);
//				restaurantCombo3.setStore(bookingStatusListStore);
//				restaurantCombo3.setForceSelection(true);
//				restaurantCombo3.setVisible(false);
//				lc3.add(restaurantCombo3, new ColumnData(150));

				fromDateField1 = new IEFriendlyDateField();
				fromDateField1.setId("RestaurantsPanel_fromDateField1");
				fromDateField1.setEmptyText(CoreConstants.CORE_CONSTANTS.form() + " "
						+ CoreConstants.CORE_CONSTANTS.date());
				fromDateField1.setMessageTarget("tooltip");
				fromDateField1.setStyleAttribute(CServiceConstants.CSS_MARGINLEFT, "20px");
				fromDateField1.setVisible(false);
				lc1.add(fromDateField1, new ColumnData(150));
				fromDateField1.addListener(Events.Change, new Listener<BaseEvent>() {
					@Override
					public void handleEvent(BaseEvent be) {
						if (toDateField1.getValue() != null) {
							if (fromDateField1.getValue() != null) {
								if (toDateField1.getValue().getTime() >= fromDateField1.getValue().getTime()) {
									fromDateField1.clearInvalid();
									toDateField1.clearInvalid();
								}
							}
						}
					}
				});
				fromDateField1.setValidator(new Validator() {
					@Override
					public String validate(Field<?> field, String value) {
						if (toDateField1.getValue() != null) {
							if (value != null) {
								if (toDateField1.getValue().getTime() < fromDateField1.getValue().getTime()) {
									return CServiceConstants.CSERVICE_CONSTANTS.greaterStartThanEndDate();
								}
							}
						}
						return null;
					}
				});

				fromDateField2 = new IEFriendlyDateField();
				fromDateField2.setId("RestaurantsPanel_fromDateField2");
				fromDateField2.setEmptyText(CoreConstants.CORE_CONSTANTS.form() + " "
						+ CoreConstants.CORE_CONSTANTS.date());
				fromDateField2.setMessageTarget("tooltip");
				fromDateField2.setStyleAttribute(CServiceConstants.CSS_MARGINLEFT, "20px");
				fromDateField2.setVisible(false);
				lc2.add(fromDateField2, new ColumnData(150));
				fromDateField2.addListener(Events.Change, new Listener<BaseEvent>() {
					@Override
					public void handleEvent(BaseEvent be) {
						if (toDateField2.getValue() != null) {
							if (fromDateField2.getValue() != null) {
								if (toDateField2.getValue().getTime() >= fromDateField2.getValue().getTime()) {
									fromDateField2.clearInvalid();
									toDateField2.clearInvalid();
								}
							}
						}
					}
				});
				fromDateField2.setValidator(new Validator() {
					@Override
					public String validate(Field<?> field, String value) {
						if (toDateField2.getValue() != null) {
							if (value != null) {
								if (toDateField2.getValue().getTime() < fromDateField2.getValue().getTime()) {
									return CServiceConstants.CSERVICE_CONSTANTS.greaterStartThanEndDate();
								}
							}
						}
						return null;
					}
				});

				fromDateField3 = new IEFriendlyDateField();
				fromDateField3.setId("RestaurantsPanel_fromDateField3");
				fromDateField3.setEmptyText(CoreConstants.CORE_MESSAGES.operation(
						CoreConstants.CORE_CONSTANTS.from(), CoreConstants.CORE_CONSTANTS.date()));
				fromDateField3.setMessageTarget("tooltip");
				fromDateField3.setStyleAttribute(CServiceConstants.CSS_MARGINLEFT, "20px");
				fromDateField3.setVisible(false);
				lc3.add(fromDateField3, new ColumnData(150));
				fromDateField3.addListener(Events.Change, new Listener<BaseEvent>() {
					@Override
					public void handleEvent(BaseEvent be) {
						if (toDateField3.getValue() != null) {
							if (fromDateField3.getValue() != null) {
								if (toDateField3.getValue().getTime() >= fromDateField3.getValue().getTime()) {
									fromDateField3.clearInvalid();
									toDateField3.clearInvalid();
								}
							}
						}
					}
				});
				fromDateField3.setValidator(new Validator() {
					@Override
					public String validate(Field<?> field, String value) {
						if (toDateField3.getValue() != null) {
							if (value != null) {
								if (toDateField3.getValue().getTime() < fromDateField3.getValue().getTime()) {
									return CServiceConstants.CSERVICE_CONSTANTS.greaterStartThanEndDate();
								}
							}
						}
						return null;
					}
				});

				toDateField1 = new IEFriendlyDateField();
				toDateField1.setId("RestaurantsPanel_toDateField1");
				toDateField1.setEmptyText(CoreConstants.CORE_MESSAGES.operation(
						CoreConstants.CORE_CONSTANTS.to(), CoreConstants.CORE_CONSTANTS.date()));
				toDateField1.setMessageTarget("tooltip");
				toDateField1.setStyleAttribute(CServiceConstants.CSS_MARGINLEFT, "20px");
				toDateField1.setVisible(false);
				lc1.add(toDateField1, new ColumnData(150));
				toDateField1.addListener(Events.Change, new Listener<BaseEvent>() {

					@Override
					public void handleEvent(BaseEvent be) {
						if (fromDateField1.getValue() != null) {
							if (toDateField1.getValue() != null) {
								if (fromDateField1.getValue().getTime() <= toDateField1.getValue().getTime()) {
									toDateField1.clearInvalid();
									fromDateField1.clearInvalid();
								}
							}
						}
					}
				});
				toDateField1.setValidator(new Validator() {
					@Override
					public String validate(Field<?> field, String value) {
						if (fromDateField1.getValue() != null) {
							if (value != null) {
								if (toDateField1.getValue().getTime() < fromDateField1.getValue().getTime()) {
									return CServiceConstants.CSERVICE_CONSTANTS.greaterStartThanEndDate();
								}
							}
						}
						return null;
					}
				});

				toDateField2 = new IEFriendlyDateField();
				toDateField2.setId("RestaurantsPanel_toDateField2");
				toDateField2.setEmptyText(CoreConstants.CORE_MESSAGES.operation(
						CoreConstants.CORE_CONSTANTS.to(), CoreConstants.CORE_CONSTANTS.date()));
				toDateField2.setMessageTarget("tooltip");
				toDateField2.setStyleAttribute(CServiceConstants.CSS_MARGINLEFT, "20px");
				toDateField2.setVisible(false);
				lc2.add(toDateField2, new ColumnData(150));
				toDateField2.addListener(Events.Change, new Listener<BaseEvent>() {

					@Override
					public void handleEvent(BaseEvent be) {
						if (fromDateField2.getValue() != null) {
							if (toDateField2.getValue() != null) {
								if (fromDateField2.getValue().getTime() <= toDateField2.getValue().getTime()) {
									toDateField2.clearInvalid();
									fromDateField2.clearInvalid();
								}
							}
						}
					}
				});
				toDateField2.setValidator(new Validator() {
					@Override
					public String validate(Field<?> field, String value) {
						if (fromDateField2.getValue() != null) {
							if (value != null) {
								if (toDateField2.getValue().getTime() < fromDateField2.getValue().getTime()) {
									return CServiceConstants.CSERVICE_CONSTANTS.greaterStartThanEndDate();
								}
							}
						}
						return null;
					}
				});

				toDateField3 = new IEFriendlyDateField();
				toDateField3.setId("RestaurantsPanel_toDateField3");
				toDateField3.setEmptyText(CoreConstants.CORE_MESSAGES.operation(
						CoreConstants.CORE_CONSTANTS.to(), CoreConstants.CORE_CONSTANTS.date()));
				toDateField3.setMessageTarget("tooltip");
				toDateField3.setStyleAttribute(CServiceConstants.CSS_MARGINLEFT, "20px");
				toDateField3.setVisible(false);
				lc3.add(toDateField3, new ColumnData(150));
				toDateField3.addListener(Events.Change, new Listener<BaseEvent>() {

					@Override
					public void handleEvent(BaseEvent be) {
						if (fromDateField3.getValue() != null) {
							if (toDateField3.getValue() != null) {
								if (fromDateField3.getValue().getTime() <= toDateField3.getValue().getTime()) {
									toDateField3.clearInvalid();
									fromDateField3.clearInvalid();
								}
							}
						}
					}
				});
				toDateField3.setValidator(new Validator() {
					@Override
					public String validate(Field<?> field, String value) {
						if (fromDateField3.getValue() != null) {
							if (value != null) {
								if (toDateField3.getValue().getTime() < fromDateField3.getValue().getTime()) {
									return CServiceConstants.CSERVICE_CONSTANTS.greaterStartThanEndDate();
								}
							}
						}
						return null;
					}
				});

				guestTypeStore = new ListStore<GuestProfileTypeEnumModelData>();
				guestTypeCombo1 = new EasyClearCombobox<GuestProfileTypeEnumModelData>();
				
				for(GuestProfileTypeGWTEnum fsi : GuestProfileTypeGWTEnum.values()){
					guestTypeStore.add(new GuestProfileTypeEnumModelData(fsi));
				}
				
				guestTypeCombo1.setId("RestaurantsPanel_guestTypeCombo1");
				guestTypeCombo1.setStyleAttribute(CServiceConstants.CSS_MARGINLEFT, "20px");
				guestTypeCombo1.setDisplayField(CoreConstants.FULLTNAME);
				guestTypeCombo1.setEmptyText(CServiceConstants.CSERVICE_CONSTANTS.guestType());
				guestTypeCombo1.setTriggerAction(TriggerAction.ALL);
				guestTypeCombo1.setStore(guestTypeStore);
				guestTypeCombo1.setForceSelection(true);
				guestTypeCombo1.setVisible(false);
				lc1.add(guestTypeCombo1, new ColumnData(150));

				guestTypeCombo2 = new EasyClearCombobox<GuestProfileTypeEnumModelData>();
				guestTypeCombo2.setId("RestaurantsPanel_guestTypeCombo2");
				guestTypeCombo2.setStyleAttribute(CServiceConstants.CSS_MARGINLEFT, "20px");
				guestTypeCombo2.setEmptyText(CServiceConstants.CSERVICE_CONSTANTS.guestType());
				guestTypeCombo2.setDisplayField(CoreConstants.FULLTNAME);
				guestTypeCombo2.setTriggerAction(TriggerAction.ALL);
				guestTypeCombo2.setStore(guestTypeStore);
				guestTypeCombo2.setForceSelection(true);
				guestTypeCombo2.setVisible(false);
				lc2.add(guestTypeCombo2, new ColumnData(150));

				guestTypeCombo3 = new EasyClearCombobox<GuestProfileTypeEnumModelData>();
				guestTypeCombo3.setId("RestaurantsPanel_guestTypeCombo3");
				guestTypeCombo3.setStyleAttribute(CServiceConstants.CSS_MARGINLEFT, "20px");
				guestTypeCombo3.setEmptyText(CServiceConstants.CSERVICE_CONSTANTS.guestType());
				guestTypeCombo3.setDisplayField(CoreConstants.FULLTNAME);
				guestTypeCombo3.setTriggerAction(TriggerAction.ALL);
				guestTypeCombo3.setStore(guestTypeStore);
				guestTypeCombo3.setForceSelection(true);
				guestTypeCombo3.setVisible(false);
				lc3.add(guestTypeCombo3, new ColumnData(150));

				lc1.setStyleAttribute(CServiceConstants.CSS_MARGINLEFT, "10px");

				lc2.setStyleAttribute(CServiceConstants.CSS_MARGINLEFT, "10px");
				lc2.setStyleAttribute(CServiceConstants.CSS_MARGINTOP, "20px");

				lc3.setStyleAttribute(CServiceConstants.CSS_MARGINLEFT, "10px");
				lc3.setStyleAttribute(CServiceConstants.CSS_MARGINTOP, "20px");
				
				searchBtnBarHp = new HorizontalPanel();
				searchBtnBarHp.setSpacing(5);
				searchBtnBarHp.setId("RestaurantsPanel_searchBtnBarHp");

				searchBtnLeftHp = new HorizontalPanel();
				searchBtnLeftHp.setId("RestaurantsPanel_searchBtnLeftHp");
				searchBtnLeftHp.setStyleAttribute(CServiceConstants.CSS_MARGINLEFT, "380px");
				searchBtnBarHp.add(searchBtnLeftHp);
				
				searchBtnRightHp = new HorizontalPanel();
				searchBtnRightHp.setId("RestaurantsPanel_searchBtnRightHp");
				searchBtnBarHp.add(searchBtnRightHp);
				
				searchButton = new FormButton(CoreConstants.CORE_CONSTANTS.search());
				searchButton.setStyleAttribute(CServiceConstants.CSS_MARGINLEFT, "20px");
				searchButton.setId("RestaurantsPanel_searchButton");
				searchButton.addSelectionListener(new SelectionListener<ButtonEvent>() {

					@Override
					public void componentSelected(ButtonEvent ce) {
						boolean isValid;
						if ((firstName1.isVisible() && !firstName1.isValid())
								|| (firstName2.isVisible() && !firstName2.isValid())
								|| (firstName3.isVisible() && !firstName3.isValid())
								|| (lastName1.isVisible() && !lastName1.isValid())
								|| (lastName2.isVisible() && !lastName2.isValid())
								|| (lastName3.isVisible() && !lastName3.isValid())) {
							isValid = false;
						} else {
							isValid = true;
						}
						if (isValid) {
							submit(SubmitType.DEFAULT);
							searchButton.removeStyleName(CoreConstants.CSS_FORM_BUTTON_FOCUS);
						}
					}
				});
				searchBtnRightHp.add(searchButton);
				
				final FormButton cancelBtn = new FormButton(CoreConstants.CORE_CONSTANTS.cancel());
				cancelBtn.setId("AdvancedSearchDialog_cbtn_button");
				cancelBtn.addSelectionListener(new SelectionListener<ButtonEvent>() {
					@Override
					public void componentSelected(ButtonEvent ce) {
						InRoomDiningAdvancedDialog.this.hide();
						cancelBtn.removeStyleName(CoreConstants.CSS_FORM_BUTTON_FOCUS);
					}
				});
				searchBtnBarHp.add(cancelBtn);
				
				formPanel.add(lc1);
				formPanel.add(lc2);
				formPanel.add(lc3);
				vp.add(searchBtnBarHp);
				add(vp);
			}

			searchItemView(0, 1);
			searchItemView(1, 2);
			searchItemView(2, 3);
			buildStore();
			onShow();

		}

		@Override
		public void setFocus() {
			
		}

		@Override
		public void updateForm(BookingView entity) {
			
		}

		@Override
		public void populateEntity(BookingView entity) {
			
		}

	}

//	protected void newSearch() {
//		String term = null;
//		MainPaginationSearchModel sm = new MainPaginationSearchModel();
//		sm.setSearchTerm(term);
//		myGrid.newSearch(sm);
//	}

	private void buildStore() {
		searchItemListStore1.removeAll();
		for (int i = 0; i < searchItemListStore.getCount(); i++) {
			if ((searchItemCombo2.getValue().getEnum().getIndex() != searchItemListStore.getAt(i).getEnum()
					.getIndex())
					&& (searchItemCombo3.getValue().getEnum().getIndex() != searchItemListStore.getAt(i)
							.getEnum().getIndex())) {
				searchItemListStore1.add(searchItemListStore.getAt(i));
			}
		}

		searchItemListStore2.removeAll();
		for (int i = 0; i < searchItemListStore.getCount(); i++) {
			if ((searchItemCombo1.getValue().getEnum().getIndex() != searchItemListStore.getAt(i).getEnum()
					.getIndex())
					&& (searchItemCombo3.getValue().getEnum().getIndex() != searchItemListStore.getAt(i)
							.getEnum().getIndex())) {
				searchItemListStore2.add(searchItemListStore.getAt(i));
			}
		}

		searchItemListStore3.removeAll();
		for (int i = 0; i < searchItemListStore.getCount(); i++) {
			if ((searchItemCombo1.getValue().getEnum().getIndex() != searchItemListStore.getAt(i).getEnum()
					.getIndex())
					&& (searchItemCombo2.getValue().getEnum().getIndex() != searchItemListStore.getAt(i)
							.getEnum().getIndex())) {
				searchItemListStore3.add(searchItemListStore.getAt(i));
			}
		}

	}

	private void searchItemView(int code, int row) {
		switch (code) {
		case 0:
			switch (row) {
			case 1:
				firstName1.clear();
				lastName1.clear();
				firstName1.setVisible(true);
				lastName1.setVisible(true);
				bookingStatusCombo1.setVisible(false);
				fromDateField1.setVisible(false);
				toDateField1.setVisible(false);
				guestTypeCombo1.setVisible(false);
				break;
			case 2:
				firstName2.clear();
				lastName2.clear();
				firstName2.setVisible(true);
				lastName2.setVisible(true);
				bookingStatusCombo2.setVisible(false);
				fromDateField2.setVisible(false);
				toDateField2.setVisible(false);
				guestTypeCombo2.setVisible(false);
				break;
			case 3:
				firstName3.clear();
				lastName3.clear();
				firstName3.setVisible(true);
				lastName3.setVisible(true);
				bookingStatusCombo3.setVisible(false);
				fromDateField3.setVisible(false);
				toDateField3.setVisible(false);
				guestTypeCombo3.setVisible(false);
				break;
			}
			break;
		case 1:
			switch (row) {
			case 1:
				firstName1.clear();
				lastName1.clear();
				firstName1.setVisible(false);
				lastName1.setVisible(false);
				bookingStatusCombo1.setVisible(true);
				fromDateField1.setVisible(false);
				toDateField1.setVisible(false);
				guestTypeCombo1.setVisible(false);
				break;
			case 2:
				firstName2.clear();
				lastName2.clear();
				firstName2.setVisible(false);
				lastName2.setVisible(false);
				bookingStatusCombo2.setVisible(true);
				fromDateField2.setVisible(false);
				toDateField2.setVisible(false);
				guestTypeCombo2.setVisible(false);
				break;
			case 3:
				firstName3.clear();
				lastName3.clear();
				firstName3.setVisible(false);
				lastName3.setVisible(false);
				bookingStatusCombo3.setVisible(true);
				fromDateField3.setVisible(false);
				toDateField3.setVisible(false);
				guestTypeCombo3.setVisible(false);

				break;
			}
			break;
		case 2:
			switch (row) {
			case 1:
				firstName1.clear();
				lastName1.clear();
				firstName1.setVisible(false);
				lastName1.setVisible(false);
				bookingStatusCombo1.setVisible(false);
//				restaurantCombo1.setVisible(false);
				fromDateField1.setVisible(true);
				toDateField1.setVisible(true);
				guestTypeCombo1.setVisible(false);
				break;
			case 2:
				firstName2.clear();
				lastName2.clear();
				firstName2.setVisible(false);
				lastName2.setVisible(false);
				bookingStatusCombo2.setVisible(false);
//				restaurantCombo2.setVisible(false);
				fromDateField2.setVisible(true);
				toDateField2.setVisible(true);
				guestTypeCombo2.setVisible(false);
				break;
			case 3:
				firstName3.clear();
				lastName3.clear();
				firstName3.setVisible(false);
				lastName3.setVisible(false);
				bookingStatusCombo3.setVisible(false);
//				restaurantCombo3.setVisible(false);
				fromDateField3.setVisible(true);
				toDateField3.setVisible(true);
				guestTypeCombo3.setVisible(false);
				break;
			}
			break;
		case 3:
			switch (row) {
			case 1:
				firstName1.clear();
				lastName1.clear();
				firstName1.setVisible(false);
				lastName1.setVisible(false);
				bookingStatusCombo1.setVisible(false);
//				restaurantCombo1.setVisible(false);
				fromDateField1.setVisible(false);
				toDateField1.setVisible(false);
				guestTypeCombo1.setVisible(true);
				break;
			case 2:
				firstName2.clear();
				lastName2.clear();
				firstName2.setVisible(false);
				lastName2.setVisible(false);
				bookingStatusCombo2.setVisible(false);
//				restaurantCombo2.setVisible(false);
				fromDateField2.setVisible(false);
				toDateField2.setVisible(false);
				guestTypeCombo2.setVisible(true);
				break;
			case 3:
				firstName3.clear();
				lastName3.clear();
				firstName3.setVisible(false);
				lastName3.setVisible(false);
				bookingStatusCombo3.setVisible(false);
//				restaurantCombo3.setVisible(false);
				fromDateField3.setVisible(false);
				toDateField3.setVisible(false);
				guestTypeCombo3.setVisible(true);
				break;
			}
			break;
		}
	}

	@Override
	public void show() {
		super.show();
	}
	
	@Override
	public void hide() {
		super.hide();
		firstName1.clear();
		firstName2.clear();
		firstName3.clear();
		lastName1.clear();
		lastName2.clear();
		lastName3.clear();
		bookingStatusCombo1.clear();
		bookingStatusCombo2.clear();
		bookingStatusCombo3.clear();
		guestTypeCombo1.clear();
		guestTypeCombo2.clear();
		guestTypeCombo3.clear();
		fromDateField1.clear();
		fromDateField2.clear();
		fromDateField3.clear();
		toDateField1.clear();
		toDateField2.clear();
		toDateField3.clear();
	}

	@Override
	public void formSubmitCallBack(FcsFormPanel<BookingViewModelData> form, SubmitType submitType) {
	}

	@Override
	protected FcsFormPanel<BookingView> getFormPanel() {
		return null;
	}


}
